<?php
require_once 'CMS/Util.php';
require_once 'CMS/User.php';
require_once 'CMS/Mvc/BaseController.php';
require_once 'CMS/Mvc/BaseAdminController.php';
require_once 'CMS/AdminCommon.php';

//Người tạo : Lại Ngọc Thái Châu - Team 0
//Module 	: login
//Chức năng	: Quản lý login vao page admin

class Admin_LoginController extends BaseAdminController {
		
	public function init(){
		parent::init();
		$this->_helper->layout()->setLayout('layoutadmin');
		$session = new Zend_Session_Namespace('login.auth');
		if(isset($session->id_user))
		{
			header("location: /admin/index");
		}
	}
	
	public function indexAction(){
		//mun session o dau
		$user = new User();
		$warning="";
		if(isset($_POST) && $_POST!=null)
		{
			if($_POST["username"]=="" || $_POST["password"]=="")
			{
				$warning = "No match for Username and/or Password.";
			}
			else 
			{ 
				if($_POST["username"]!="" && $_POST["password"]!="" && $user->login($_POST["username"], $_POST["password"])!=true)
				{
					$warning = "No match for Username and/or Password 1 2 3.";
				}
				else 
				{
					header("location: /admin/index");
				}	
			}
		}
		
		//Start ------- Truyền Parameter qua View
		$this->view->warning = $warning;
		$this->view->actionUrl = "/admin/login";
		//End ------- Truyền Parameter qua View
	}
	
	
	public function logoutAction(){
		$session = new Zend_Session_Namespace('login.auth');
		unset($session->id_user);
		unset($session->permission);
		header("location: /admin/login");	
	}

}